package city

import (
	"context"
	"wh-1-backend/internal/dao"
	"wh-1-backend/internal/model"
	"wh-1-backend/internal/service"
)

type sCity struct{}

func New() *sCity {
	return &sCity{}
}

func init() {
	service.RegisterCity(New())
}

func (c *sCity) ListByPid(ctx context.Context, pid uint) (res []*model.CityList, err error) {
	err = dao.City.Ctx(ctx).Where(dao.City.Columns().Pid, pid).Scan(&res)
	return
}

func (c *sCity) List(ctx context.Context) (res []*model.CityList, err error) {
	err = dao.City.Ctx(ctx).Scan(&res)
	return
}

func (c *sCity) ListByIds(ctx context.Context, ids []uint) (res []*model.CityList, err error) {
	err = dao.City.Ctx(ctx).WhereIn(dao.City.Columns().Id, ids).Scan(&res)
	return
}
